﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors;
using MINERP.BLL.InfoConfig;
using MINERP.DAL;
using MINERP.MODEL.InfoConfig;

namespace MINERP.InfoConfig.Controller
{
    public class ActionController
    {
        #region //private fields

        private ActionBLL _bll = new ActionBLL();
        private GridControl _grid = null;
        private GridView _view = null;
        private ComboBoxEdit _comboBox = null;
        private GroupControl _groupControl = null;
        private CheckEdit _checkEdit = null;

        #endregion


        #region //Public Properties

        internal GroupControl GroupControl
        {
            set
            {
                _groupControl = value;
            }
        }
        internal CheckEdit CheckEdit
        {
            set
            {
                _checkEdit = value;
            }
        }
        internal ComboBoxEdit ComoBox
        {
            set
            {
                _comboBox = value;
            }
        }
        internal GridControl Grid
        {
            set
            {
                _grid = value;
            }
        }

        internal GridView View
        {
            set
            {
                this._view = value;
            }
            get
            {
                return _view;
            }
        }

        #endregion


        #region //Public Methods
        /// <summary>
        /// 
        /// </summary>
        public void GetData()
        {
            _grid.DataSource = _bll.GetActionList();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public tb_Action GetActionObj(int id)
        {
            return _bll.GetActionObj(id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void Add(tb_Action obj)
        {
            UserRoleBLL roleBLL = new UserRoleBLL();
            tb_Power power = roleBLL.GetPowerObj(_comboBox.Text);
            obj.tb_Power = power;
            _bll.Add(obj);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void Update(tb_Action obj)
        {
            UserRoleBLL roleBLL = new UserRoleBLL();
            tb_Power power = roleBLL.GetPowerObj(_comboBox.Text);
            obj.tb_Power = power;
            _bll.Update();
        }
        public void Delete(tb_Action obj)
        {
            _bll.Delete(obj);
        }
        /// <summary>
        /// 
        /// </summary>
        public void LinkRole()
        {
            UserRoleBLL roleBLL = new UserRoleBLL();
            _comboBox.Properties.Items.Clear();
            foreach (var item in roleBLL.GetRoleList())
            {
                _comboBox.Properties.Items.Add(item.Name);
            }
        }
        #endregion
    }
}
